package com.smallchill.common.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.smallchill.common.dao.DaoMaker;
import com.smallchill.common.publish.PublisherCenter;
import com.smallchill.core.cache.EhcacheFactory;
import com.smallchill.core.constant.Cst;
import com.smallchill.core.db.DAOManager;
import com.smallchill.core.utils.Prop;

public class SysListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		globalSetting();
		daoSetting();
		PublisherCenter.publish();
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		destory();
	}
	
	
	public void globalSetting() {
		Prop prop = Prop.init("config.properties");
		Cst.me().setDevMode(prop.getBoolean("config.devMode", false));
		Cst.me().setDefaultCacheFactory(new EhcacheFactory());
	}
	
	public void daoSetting() {
		DAOManager.init().register("master", DaoMaker.makeSqlManager());
	}
	
	public void destory() {
		DAOManager.init().destroy();
	}

}